'''
Coron Lattice Drawer Mode 2
Author: Victor Codocedo H.
Universidad Tecnica Federico Santa Maria

Usage:
python drawer_mode2.py lats/baclat.lat

Cleans Extent top-down

baclat.lat is the output of LECO from Coron.
Add names, extension and stability options when executing LECO.
LECO is provided on Coron
!#/usr/bin/python
'''
from vtk import *
import sys, getopt
from latexp.lattice.definitions import *
from latexp.lattice.functions import *
from latexp.graphic.lattice import Drawer
from latexp.plugins.SubLatticeSelector import Selector
from cfgmng import read_cfg
import argparse

def draw_lattice(lattice,config):
# GRAPH AS DIRECTED
    g=vtkMutableDirectedGraph()

    
# CREATE GRAPHIC LATTICE
    glattice = GraphicLattice.fromConceptLattice(lattice)
    drawer = Drawer(lattice,glattice,config,Selector)
    plugin = Selector(drawer)
    drawer.draw()

# PRINTING SUMMARY
    for i in range(lattice.GetNumberOfLevels()):
        print "Cantidad de Conceptos del nivel " + str(i) + ": " + str(len(lattice.GetConceptsByLevel(i)))

if __name__ == '__main__':
    '''
    #####################################################
    ######## MAIN CODE ##################################
    #####################################################
    '''
    parser = argparse.ArgumentParser()
    parser.add_argument("-i", "--inputfile", dest="lat_path",
                        help="Path to the lattice", metavar="FILE",required=True)
    
    parser.add_argument("-s", "--stability", dest="stab", action="store",type=float,default=0.0,
                      help="Stability threshold", metavar="[0,1]")
    parser.add_argument("-c", "--config",
                      action="store", dest="cfg_path", default="cfg/lattice_drawer.cfg",metavar="FILE",
                      help="Configuration for the lattice outlay")
    parser.add_argument("-q", "--quiet",
                      action="store_false", dest="verbose", default=True,
                      help="put a threshold of stability for drawing the lattice")
    
    args = parser.parse_args()
    print args,args.lat_path
    
    config = read_cfg(args.cfg_path)
    print config.get("Text","font")
    print "--> Reading lattice"
    lattice = readLattice(args.lat_path)
    draw_lattice(lattice,config)

    